package DrugManagement

import (
	"MedicalTreatment/global"
	model "MedicalTreatment/model"
	"github.com/gin-gonic/gin"
)

func DrugIncrease(r *gin.Engine) {
	r.POST("/drugAdd", func(context *gin.Context) {
		var drug model.Drug
		if err := context.ShouldBindJSON(&drug); err != nil {
			context.JSON(200, gin.H{
				"Msg": err,
			})
			return
		}
		a := global.DB.Model(model.Drug{}).Where("name = ?", drug.Name).First(&drug).RowsAffected
		if a == 0 {
			if err := global.DB.Create(&drug).Error; err != nil {
				context.JSON(200, gin.H{
					"Msg": err,
				})
			} else {
				context.JSON(200, gin.H{
					"Msg": "创建成功",
				})
			}
		} else {
			context.JSON(200, gin.H{
				"Msg": "药品重复",
			})
		}

	})
}
